package taskhandler

import (
	"cvevulner/util"
	"fmt"
	"github.com/astaxie/beego/logs"
)

//AddCommentToIssue Add a comment to the issue
func AddCommentToIssue(msg, issueNum, owner, repo, access string) {
	url := fmt.Sprintf(`https://gitee.com/api/v5/repos/%v/%v/issues/%v/comments`, owner, repo, issueNum)
	param := fmt.Sprintf(`{"access_token": "%s","body":"%s"}`, access, msg)
	res, err := util.HTTPPost(url, param)
	if err != nil {
		logs.Error(err, msg)
	}
	logs.Info("Add comment back:", res, msg)
}

//SendPrivateLetters Send a private message to a gitee user
func SendPrivateLetters(access, content, useName string) {
	url := "https://gitee.com/api/v5/notifications/messages"
	param := fmt.Sprintf(`{"access_token":"%s","username":"%s","content":"%s"}`, access, useName, content)
	res, err := util.HTTPPost(url, param)
	if err != nil {
		logs.Error(err)
	}
	logs.Info("Send private message:", res)
}
